/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pig.demo.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.pig.demo.entity.XlmIndexImg;
import com.pig4cloud.pig.demo.service.XlmIndexImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * @author pig code generator
 * @date 2022-04-14 16:05:35
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/lbt")
@Api(value = "lbt", tags = "轮播图管理")
public class XlmIndexImgController {

    private final XlmIndexImgService xlmIndexImgService;

    /**
     * 分页查询
     *
     * @param page        分页对象
     * @param xlmIndexImg
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('demo_xlmindeximg_get')")
    public R getXlmIndexImgPage(Page page, XlmIndexImg xlmIndexImg) {
        return R.ok(xlmIndexImgService.page(page, Wrappers.query(xlmIndexImg)));
    }


    /**
     * 通过id查询
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('demo_xlmindeximg_get')")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(xlmIndexImgService.getById(id));
    }

    /**
     * 新增
     *
     * @param xlmIndexImg
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SysLog("新增")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('demo_xlmindeximg_add')")
    public R save(@RequestBody XlmIndexImg xlmIndexImg) {
        return R.ok(xlmIndexImgService.save(xlmIndexImg));
    }

    /**
     * 修改
     *
     * @param xlmIndexImg
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SysLog("修改")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('demo_xlmindeximg_edit')")
    public R updateById(@RequestBody XlmIndexImg xlmIndexImg) {
        return R.ok(xlmIndexImgService.updateById(xlmIndexImg));
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SysLog("通过id删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('demo_xlmindeximg_del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(xlmIndexImgService.removeById(id));
    }

    /**
     * list
     *
     * @param id id
     */
    @ApiOperation(value = "list", notes = "list")
    @SysLog("list")
    @GetMapping("/list")
    @Inner(value = false)
    public R list() {
        return R.ok(xlmIndexImgService.list());
    }

}
